<?php
class account extends ujn_controller {
	var $main_url = '';
	var $login_url = '';
	
	function _before() {
		$this->main_url = ujn::getCFG('plat.url.main_url');
		$this->login_url = ujn::getCFG('plat.url.login_url');
	}	

	function get_user(){
		$uid  = (isset($_REQUEST['uid']) && !empty($_REQUEST['uid'])) ? (int)$_REQUEST['uid'] : 0;
		$puid = (isset($_REQUEST['puid']) && !empty($_REQUEST['puid'])) ? $_REQUEST['puid'] : '0';
		
		$data = array();
		$url = '';
		if( !empty($puid) ) {
			$url = $this->login_url . '_hookdoor/_datadoor.php?cmd=get_uid&puid=' . $puid;
			$temp = tls_func::rest_request('GET', $url, null, null, false, true);

			$data = $temp['data'];
			$uid = isset($data['uid']) ? (int)$data['uid'] : 0;
		}
		
		if( !empty( $uid ) ){
			$params	= array('p' => PLATFORM, 'uid' => $uid);
			$url = $this->main_url . '_hookdoor/_datadoor.php?member-get_user';			
			$x = tls_func::rest_request('POST', $url, null, $params, false, true);
			
			$data = $x['data']['lists'];
			$flag = $x['data']['flag'];
			
			if(!is_array($data) || isset($data['msg']) || empty($data) || !isset($data['mid']) || !$flag){ 
				$data = array();
			}
			else {
				$xurl = $this->login_url . '_hookdoor/_datadoor.php?cmd=get_puid&uid=' . $uid;
				$xdata = json_decode(file_get_contents($xurl), true);
				if(is_array($data)) $data = array_merge($data, $xdata);
			}
		}
		
		$this->assign(array(
			'uid' 	=> $uid,
			'data'	=> $data,
			'url'	=> $url,
		));
	}
	

	function get_tablelog_detail(){
		$turl = $this->main_url . '_hookdoor/_datadoor.php?logs-get_db_tables?p=' . PLATFORM . '&prefix=logmember';
		$tables = json_decode(file_get_contents($turl), true);
		$tables = (!is_array($tables) || $tables['flag'] == 0) ? array() : $tables['ret'];

		$tbl = isset($_REQUEST['tbl']) ? $_REQUEST['tbl'] : current($tables);
		$uid = isset($_REQUEST['uid']) ? $_REQUEST['uid'] : 0;
		$data = array();

		$tbl_tmp = explode('`', $tbl);
		$tbl_name = $tbl_tmp[count($tbl_tmp)-2];

		if($tbl && $uid) {
			$url = $this->main_url . '_hookdoor/_datadoor.php?logs-get_logs?p=facebook&tbl=' . $tbl_name . '&uid=' . $_REQUEST['uid'];
			$data = json_decode(file_get_contents($url), true);
			$data = (!is_array($data) || $data['flag'] == 0) ? array() : $data['ret'];
		}

		$this->assign(array(
			'tables' => $tables,
			'tbl_name' => $tbl_name,
			'data' => $data,
			'url' => array(
				$url, $turl
			),
			'uid' => $uid,
		));
	}
	
	function get_tablelog_detail_summry() { // 桌子大概信息
		$tbl = isset($_REQUEST['tbl_lm']) ? $_REQUEST['tbl_lm'] : '';
		$ltid = isset($_REQUEST['ltid']) ? $_REQUEST['ltid'] : 0;

		$url = $this->main_url . '_hookdoor/_datadoor.php?logs-'.__FUNCTION__.'?p='. PLATFORM .'&tbl=' . $tbl . '&ltid=' . $ltid;
		$data = json_decode(file_get_contents($url), true);

		$data = (!is_array($data) || $data['flag'] == 0) ? array() : $data['ret'];	
		$this->assign(array(
						'data' => $data
				));
	}	
	
	//start_deal:7-49,42,43,4-1;start_deal:8-35,27,1,2-1;chip_in:8-5;chip_in:7-15;chip_in:8-15;
	function get_tablelog_detail_all() { // 全部信息
		$tbl = isset($_REQUEST['tbl_lm']) ? $_REQUEST['tbl_lm'] : '';
		$ltid = isset($_REQUEST['ltid']) ? $_REQUEST['ltid'] : 0;

		// 转换 logmember 到 logtable
		$tbl = str_replace('logmember', 'logtable', $tbl);

		$url = $this->main_url . '_hookdoor/_datadoor.php?logs-'.__FUNCTION__.'?p='. PLATFORM .'&tbl=' . $tbl . '&ltid=' . $ltid;
		$data = json_decode(file_get_contents($url), true);
		$data = (!is_array($data) || $data['flag'] == 0) ? array() : $data['ret'];	
		$temp = current($data);
		$l = explode(';', $temp['content']);
		$c = array();
		foreach($l as $k => $v) {
			$t = explode(':', $v);
			if(!empty($t[0]) && !empty($t[1])) {
				$c[$k]['title'] = $t[0];
				$detail = explode('-', $t[1]);
				if(count($detail) == 3) {
					$c[$k]['detail']['mid'] = $detail[0];
					$c[$k]['detail']['pokers'] = explode(',', $detail[1]);
					$c[$k]['detail']['chip'] = $detail[2];
				}else {
					$c[$k]['detail']['mid'] = $detail[0];
					$c[$k]['detail']['chip'] = $detail[1];
				}
			}
		}

		$this->assign(array(
			'data' => $c,
		));
	}	
}